<html>
<head><meta charset="utf-8"><title>rustc unique CrateIds · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html">rustc unique CrateIds</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="224604002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224604002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224604002">(Jan 30 2021 at 20:40)</a>:</h4>
<p>How does rustc ensure <code>CrateId</code>s are unique? <code>DefId</code>s are used to index results (e.g. the type of a function) and if two crates had the same <code>CrateId</code> within a compilation session, all havoc would break loose.</p>



<a name="224604029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224604029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224604029">(Jan 30 2021 at 20:41)</a>:</h4>
<p>A new <code>CrateId</code> is assigned every time the metadata of a new crate is loaded. This happens transparently in the metadata locator.</p>



<a name="224604072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224604072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224604072">(Jan 30 2021 at 20:42)</a>:</h4>
<p>That's what I thought, but how do you update all the uses of the old CrateId in the metadata?</p>



<a name="224604096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224604096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224604096">(Jan 30 2021 at 20:43)</a>:</h4>
<p>E.g., with this dep graph:</p>
<div class="codehilite" data-code-language="Text only"><pre><span></span><code>    A
   / \
  B   |
   \ /
    C
</code></pre></div>
<p>the metadata for B will reference C's CrateId and its own CrateId, right? Or am I misunderstanding how it works?</p>



<a name="224604144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224604144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224604144">(Jan 30 2021 at 20:44)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/fd20a8be0d74a7026267af5c9a0cd251eeaba7c6/compiler/rustc_metadata/src/rmeta/decoder.rs#L94-L96">https://github.com/rust-lang/rust/blob/fd20a8be0d74a7026267af5c9a0cd251eeaba7c6/compiler/rustc_metadata/src/rmeta/decoder.rs#L94-L96</a></p>



<a name="224604151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224604151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224604151">(Jan 30 2021 at 20:44)</a>:</h4>
<p>The metadata contains a map from <code>CrateId</code> to <code>Svh</code>. When loading the metadata, all <code>CrateId</code>'s are remapped using this map.</p>



<a name="224604455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224604455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224604455">(Jan 30 2021 at 20:52)</a>:</h4>
<p><code>Svh</code> is a hash of the whole crate, right?</p>



<a name="224604457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224604457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224604457">(Jan 30 2021 at 20:52)</a>:</h4>
<p>Or am I getting that mixed up?</p>



<a name="224604465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224604465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224604465">(Jan 30 2021 at 20:52)</a>:</h4>
<p>Yes, the <code>Svh</code> is a hash of the whole crate.</p>



<a name="224604480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224604480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224604480">(Jan 30 2021 at 20:53)</a>:</h4>
<p>Where is that map? In the link that <span class="user-mention silent" data-user-id="352985">tm</span> sent, I see a map from CrateNum to CrateNum.</p>



<a name="224604699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224604699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224604699">(Jan 30 2021 at 20:58)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/fd20a8be0d74a7026267af5c9a0cd251eeaba7c6/compiler/rustc_metadata/src/rmeta/decoder.rs#L344">https://github.com/rust-lang/rust/blob/fd20a8be0d74a7026267af5c9a0cd251eeaba7c6/compiler/rustc_metadata/src/rmeta/decoder.rs#L344</a></p>



<a name="224604700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224604700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224604700">(Jan 30 2021 at 20:58)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/blob/fd20a8be0d74a7026267af5c9a0cd251eeaba7c6/compiler/rustc_metadata/src/rmeta/decoder.rs#L94-L96">https://github.com/rust-lang/rust/blob/fd20a8be0d74a7026267af5c9a0cd251eeaba7c6/compiler/rustc_metadata/src/rmeta/decoder.rs#L94-L96</a></p>



<a name="224605441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/rustc%20unique%20CrateIds/near/224605441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/rustc.20unique.20CrateIds.html#224605441">(Jan 30 2021 at 21:16)</a>:</h4>
<p>Thanks! I'll take a look at those links :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>